package com.hkts.beltweigher.master.controller;


import com.alibaba.fastjson.JSON;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.beltweigher.master.entity.YbClassesAccumulate;
import com.hkts.beltweigher.utils.CustomPageUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.hkts.beltweigher.utils.Result;
import com.hkts.beltweigher.utils.ResultUtil;
import com.hkts.beltweigher.master.service.IInstrumentControlService;
import com.hkts.beltweigher.master.entity.InstrumentControl;

/**
 * @author hml
 * @since 2024-04-19
 */
@RestController
@RequestMapping("/order/instrumentControl")
public class InstrumentControlController {
    private final Logger logger = LoggerFactory.getLogger(InstrumentControlController.class);

    @Autowired
    public IInstrumentControlService iInstrumentControlService;

    /**
     * 分页查询数据
     *
     * @param page              分页信息
     * @param instrumentControl 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getInstrumentControlPageList")
    public Result<Object> getHontUserList(Page<InstrumentControl> page, InstrumentControl instrumentControl) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iInstrumentControlService.selectPage(page, instrumentControl)));
    }

    /**
     * 保存和修改公用的
     *
     * @param instrumentControl 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/instrumentControlSave")
    public Result<Object> instrumentControlSave(InstrumentControl instrumentControl) {
        iInstrumentControlService.saveOrUpdate(instrumentControl);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/instrumentControlGetById")
    public Result<Object> instrumentControlGetById(String id) {
        InstrumentControl byId = iInstrumentControlService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/instrumentControlDelete")
    public Result<Object> hontUserDelete(String id) {
        iInstrumentControlService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/instrumentControlBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iInstrumentControlService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }
    /**
     * 停期状态修改
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/updateStatus")
    public Result<Object> updateStatus(@RequestBody InstrumentControl instrumentControl) {
        return  iInstrumentControlService.updateStatus(instrumentControl);
    }
    /**
     * 各仪表状态查询
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/getInstrumentStatus")
    public Result<Object> getInstrumentStatus() {
        return  ResultUtil.data(iInstrumentControlService.getInstrumentStatus());
    }
}
